package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.service.GoodsTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 商品管理
 */
@RequestMapping("goodsType")
@Controller
public class GoodsTypeController {

    @Autowired
    private GoodsTypeService goodsTypeService;

    @ResponseBody
    @PostMapping("loadGoodsType")
    public String loadGoodsType() {
        return goodsTypeService.listGoodsTypeToJsonString();
    }

    @ResponseBody
    @PostMapping("save")
    public ServiceVO save(String goodsTypeName, Integer pId) {
        goodsTypeService.save(goodsTypeName, pId);
        return new ServiceVO(100, "请求成功", null);
    }

    @ResponseBody
    @PostMapping("delete")
    public ServiceVO delete(Integer goodsTypeId) {
        goodsTypeService.removeGoodsTypeById(goodsTypeId);
        return new ServiceVO(100, "请求成功", null);
    }
}
